package com.whale.utils;

import java.io.Serializable;

public class Pair<T1, T2> implements Serializable {

	private static final long serialVersionUID = 2882631591521086013L;
	
	private T1 v1;
    private T2 v2;

    public Pair(T1 v1, T2 v2) {
        this.v1 = v1;
        this.v2 = v2;
    }

    public static <T1, T2> Pair<T1, T2> newPair(T1 v1, T2 v2) {
        return new Pair<T1, T2>(v1, v2);
    }

    public void setFirst(T1 v) {
        this.v1 = v;
    }

    public T1 getFirst() {
        return v1;
    }

    public void setSecond(T2 v) {
        this.v2 = v;
    }

    public T2 getSecond() {
        return v2;
    }

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((v1 == null) ? 0 : v1.hashCode());
		result = prime * result + ((v2 == null) ? 0 : v2.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		@SuppressWarnings("rawtypes")
		Pair other = (Pair) obj;
		if (v1 == null) {
			if (other.v1 != null)
				return false;
		} else if (!v1.equals(other.v1))
			return false;
		if (v2 == null) {
			if (other.v2 != null)
				return false;
		} else if (!v2.equals(other.v2))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Pair [v1=" + v1 + ", v2=" + v2 + "]";
	}
    
}
